<?php

namespace app\qsapi\service;

use app\qsapi\model\yunPhone\YunPhoneUserMachine;
use app\qsapi\model\yunPhone\YunPhoneUserRegister;
use app\qsapi\validate\YunPhoneCreateValidate;
use think\cache\driver\Redis;

class YunPhoneService extends BaseService
{
    /**
     * Notes: 云手机获取启动参数
     * User: liubaoqiang
     * DateTime: 2024/12/16 11:05
     * @param $member_id
     * @return array
     */
    public function actionPrams($member_id): array
    {
        $userId = YunPhoneUserRegister::where(['member_id' => $member_id])->value('user_id');
        if (empty($userId)) return api_message([], '用户ID不存在', 0);
        $data = [
            'tenantId'     => env('YUN_PHONE_API.TENANT_ID'),
            'serverToken'  => env('YUN_PHONE_API.SERVER_TOKEN'),
            'appLicenseId' => env('YUN_PHONE_API.APP_LICENSE_ID'),
            'appKey'       => env('YUN_PHONE_API.APP_LICENSE_KEY'),
            'uid'          => $userId
        ];
        return api_message($data, '获取云手机启动参数成功!');
    }

    /**
     * Desc : 获取注册用户
     * User : steven
     * Desc : 注册用户后，会返回该用户的接入端点。后续此用户的所有请求都需要在该端点访问。
     * Date : 2024-03-22 13:46
     */
    public function getYunPhoneUserRegister($member_id): array
    {
        $router_url = config('yun_phone.yun_phone_router.user_register');
        $params = [
            'tenantUserId' => $member_id,
            'regionCode'   => env('YUN_PHONE_API.REGION_CODE'),
            'channelCode'  => env('YUN_PHONE_API.CHANNEL_CODE'),
        ];
        $result = self::packedData($params, $router_url);
        $code = $result['code'];
        if ($code != 1) return ['code' => 0, 'msg' => '获取注册用户失败,请稍后再试...'];
        $model = new YunPhoneUserRegister();
        $registerUser = $model->where('member_id', $member_id)->find();
        $data = [
            'user_id'        => $result['data']['userId'],
            'endpointDomain' => $result['data']['endpointDomain'],
            'endpointUrl'    => $result['data']['endpointUrl'],
            'regionCode'     => $result['data']['regionCode'],
        ];
        if ($registerUser) {
            $model->updateRow(['id' => $registerUser['id']], $data);
        } else {
            $data['member_id'] = $member_id;
            $model->insert($data);
        }
        return $result;
    }

    /**
     * Notes: 【用户】获取接入端点地址
     * User: liubaoqiang
     * DateTime: 2024/12/10 10:54
     * @param int $member_id
     * @return array
     */
    public function getYunPhoneUserAccess(int $member_id): array
    {
        $router_url = config('yun_phone.yun_phone_router.user_access');
        $user = YunPhoneUserRegister::field('user_id')->where(['member_id' => $member_id])->find();
        if (empty($user['user_id'])) return ['code' => 0, 'message' => '用户ID不存在'];
        $params = [
            'userId'     => $user['user_id'],
            'regionCode' => env('YUN_PHONE_API.REGION_CODE'),
        ];
        $result = self::packedData($params, $router_url);
        $code = $result['code'] ?? 0;
        if ($code != 1) return ['code' => 0, 'message' => '获取接入端点地址失败,请稍后再试...'];
        return $result;
    }

    /**
     * Notes: 【用户】创建并绑定云机
     * User: liubaoqiang
     * DateTime: 2024/12/10 11:14
     * @param int $member_id
     * @param array $input_params
     * @return array
     */
    public static function createYunPhoneToUser(int $member_id = 0, array $input_params = []): array
    {
        $router_url = config('yun_phone.yun_phone_router.user_create_phone');
        $user = YunPhoneUserRegister::field('user_id')->where(['member_id' => $member_id])->find();
        if (empty($user)) {
            $result = (new YunPhoneService)->getYunPhoneUserRegister($member_id);
            $user['user_id'] = $result['data']['userId'];
        }
        $validate = new YunPhoneCreateValidate();
        if (!$validate->check($input_params)) return ['code' => 0, 'msg' => $validate->getError()];
        $params = [
            'freeBuyFlag'   => 1, //0元购标识; -0：下单时不是0元购, 1：下单时是0元购
            'itemCode'      => $input_params['good_code'],  //商品编码
            'orderNo'       => $input_params['order_num'], //订单号',
            'shipmentsNum'  => intval($input_params['good_num']), //出货数量
            'userId'        => $user['user_id'], //用户ID
            'validEndTime'  => $input_params['validEndTime'], //有效时间
            'deviceAliases' => generateCode(8), //设备别名
        ];
        $result = self::packedData($params, $router_url);
        $code = $result['code'] ?? 0;
        if ($code != 1) return ['code' => 0, 'message' => $result['message'] ?? '创建并绑定云机失败,请稍后再试...'];
        $data = $result['data'] ?? [];
        if (empty($data)) return ['code' => 0, 'message' => '创建并绑定云机失败,请稍后再试...'];
        $insertData = [];
        foreach ($data as $k => $v) {
            $insertData[$k]['member_id'] = $member_id;
            $insertData[$k]['user_id'] = $v['userId'];
            $insertData[$k]['item_code'] = $input_params['good_code'];
            $insertData[$k]['user_device_id'] = $v['userDeviceId'];
            $insertData[$k]['valid_start_time'] = date('Y-m-d H:i:s');
            $insertData[$k]['valid_end_time'] = date('Y-m-d H:i:s', intval($v['validEndTime']) / 1000);
            $insertData[$k]['name'] = $params['deviceAliases'];
        }
        (new YunPhoneUserMachine())->insertAll($insertData);
        return $result;
    }


    /**
     * Notes: 【用户】获取设备列表
     * User: liubaoqiang
     * DateTime: 2024/12/10 13:23
     * @param int $member_id
     * @param $userDeviceId
     * @return array|mixed
     */
    public function getYunPhoneUserList(int $member_id, $userDeviceId = '')
    {
        $router_url = config('yun_phone.yun_phone_router.user_yun_phone_list');
        $user = YunPhoneUserRegister::field('user_id')->where(['member_id' => $member_id])->find();
        if (empty($user['user_id'])) return ['code' => 0, 'message' => '用户ID不存在'];
        $params = [
            'userId' => $user['user_id'],
            'status' => 50, //设备状态（已注销：-50，已过期：-10，使用中：50)
            'pageSize' => 9999
        ];
        if (!empty($userDeviceId)) $params['userDeviceId'] = $userDeviceId;
        $result = self::packedData($params, $router_url);
        $code = $result['code'] ?? 0;
        if ($code != 1) return ['code' => 0, 'message' => $result['message'] ?? '获取设备列表失败,请稍后再试...'];
        //将最新数据状态更新到数据库中
        $records = $result['data']['records'] ?? [];
        write_log('INFO', 'YunPhoneService.php', "云用户设备列表：" . json_encode($result, true), 'yun_user_list', true);
        if ($userDeviceId) {
            foreach ($records as $k => &$v) {
                $yunPhoneUserMachine = YunPhoneUserMachine::where(['member_id' => $member_id, 'user_device_id' => $v['userDeviceId']])->find();
                if ($yunPhoneUserMachine) {
                    $yunPhoneUserMachine->updateRow(['id' => $yunPhoneUserMachine['id']], [
                        'status'           => $v['status'],
                        'valid_start_time' => date('Y-m-d H:i:s', intval($v['validStartTime']) / 1000),
                        'valid_end_time'   => date('Y-m-d H:i:s', intval($v['validEndTime']) / 1000),
                        'onHookState'      => $v['onHookState'],
                        'displayStatus'    => $v['displayStatus'],
                        'bindStatus'       => $v['bindStatus']
                    ]);
                }
            }
        }
        $count = count($records);
        //获取当前用户所有的设备
        $nameList = (new YunPhoneUserMachine())
            ->field('user_device_id,name')
            ->where(['member_id' => $member_id, 'status' => 50, 'user_id' => $user['user_id']])
            ->select()->toArray();
        $nameList = array_column($nameList, 'name', 'user_device_id');
        foreach ($records as $k => &$v) {
            $v['userDeviceId'] = (string)$v['userDeviceId'];
            $v['tenantId'] = (string)$v['tenantId'];
            $v['userId'] = (string)$v['userId'];
            $v['resourcePoolId'] = (string)$v['resourcePoolId'];
            $v['deviceAliases'] = $nameList[$v['userDeviceId']] ?? '我的设备' . ($count - $k);
        }
        $result['data']['records'] = $records;
        return $result;
    }

    /**
     * Notes: 【用户】续费功能
     * User: liubaoqiang
     * DateTime: 2024/12/10 13:58
     * @param int $member_id
     * @param string $userDeviceId
     * @param int $increaseHour 增加的有效时长（单位：小时）
     * @return array|mixed
     */
    public static function renewYunPhoneUser(int $member_id = 0, string $userDeviceId = '', int $increaseHour = 0)
    {
        $machine = YunPhoneUserMachine::where(['member_id' => $member_id, 'user_device_id' => $userDeviceId])->find();
        $user = YunPhoneUserRegister::field('user_id')->where(['member_id' => $member_id])->find();
        if (empty($machine)) return ['code' => 0, 'message' => '云机不存在...'];
        $valid_end_time = strtotime($machine['valid_end_time']);
        if ($valid_end_time < time()) return ['code' => 0, 'message' => '云机已过期,无法续费...'];
        $router_url = config('yun_phone.yun_phone_router.user_renew_phone');
        $params = [
            'increaseHour' => $increaseHour,
            'userDeviceId' => $userDeviceId,
            'userId'       => $user['user_id'],
        ];
        $result = self::packedData($params, $router_url);
        write_log('INFO', 'YunPhoneService.php', "续费设备发货记录：" . json_encode($result, true), 'renew_user_yun', true);
        $code = $result['code'] ?? 0;
        if ($code != 1) return ['code' => 0, 'message' => $result['message'] ?? '续费失败,请稍后再试...'];
        $machine->save(['valid_end_time' => date('Y-m-d H:i:s', $valid_end_time + $increaseHour * 3600)]);
        return $result;
    }

    /**
     * Notes: 【用户】结束挂机功能
     * User: liubaoqiang
     * DateTime: 2024/12/10 15:00
     * @param int $member_id
     * @param string $userDeviceId
     * @return array|mixed
     */
    public static function stopYunPhoneUser(int $member_id, string $userDeviceId)
    {
        if (!$userDeviceId) return ['code' => 0, 'message' => '设备ID不能为空'];
        $router_url = config('yun_phone.yun_phone_router.user_stop_phone');
        $user = YunPhoneUserRegister::field('user_id')->where(['member_id' => $member_id])->find();
        if (empty($user['user_id'])) return ['code' => 0, 'message' => '用户ID不存在'];
        $params = [
            'userId'       => $user['user_id'],
            'userDeviceId' => $userDeviceId,
        ];
        $result = self::packedData($params, $router_url);
        write_log('INFO', 'YunPhoneService.php', "结束挂机设备：" . json_encode($result, true), 'stop_user_yun', true);
        $code = $result['code'] ?? 0;
        if ($code != 1) return ['code' => 0, 'message' => $result['message'] ?? '结束挂机失败,请稍后再试...'];
        return $result;
    }

    /**
     * Notes: 结束挂机-查询任务结果
     * User: liubaoqiang
     * DateTime: 2024/12/10 15:35
     * @param int $member_id
     * @param string $deviceBizTaskId
     * @return array|mixed
     */
    public function stopYunPhoneUserResult(int $member_id, string $deviceBizTaskId)
    {
        if (!$deviceBizTaskId) return ['code' => 0, 'message' => '设备ID不能为空'];
        $router_url = config('yun_phone.yun_phone_router.user_stop_phone_result');
        $user = YunPhoneUserRegister::field('user_id')->where(['member_id' => $member_id])->find();
        if (empty($user['user_id'])) return ['code' => 0, 'message' => '用户ID不存在'];
        $params = [
            'userId'          => $user['user_id'],
            'deviceBizTaskId' => $deviceBizTaskId,
        ];
        $result = self::packedData($params, $router_url);
        $code = $result['code'] ?? 0;
        if ($code != 1) return ['code' => 0, 'message' => $result['msg'] ?? '结束挂机查询失败,请稍后再试...'];
        return $result;
    }

    /**
     * Notes: 重启设备
     * User: liubaoqiang
     * DateTime: 2024/12/10 15:44
     * @param int $member_id
     * @param string $userDeviceId
     * @return array|mixed
     */
    public function restartYunPhoneUser(int $member_id, string $userDeviceId = '')
    {
        if (empty($userDeviceId)) return ['code' => 0, 'msg' => '设备ID不能为空'];
        $router_url = config('yun_phone.yun_phone_router.user_restart_phone');
        $user = YunPhoneUserRegister::field('user_id')->where(['member_id' => $member_id])->find();
        if (empty($user['user_id'])) return ['code' => 0, 'message' => '用户ID不存在'];
        $params = [
            'userId'       => $user['user_id'],
            'userDeviceId' => $userDeviceId,
        ];
        $result = self::packedData($params, $router_url);
        write_log('INFO', 'YunPhoneService.php', "重启云手机设备：" . json_encode($result, true), 'restart_user_yun', true);
        $code = $result['code'] ?? 0;
        if ($code != 1) return ['code' => 0, 'message' => $result['message'] ?? '重启设备失败,请稍后再试...'];
        return $result;
    }

    /**
     * Notes:【用户】重启设备记录,重启云手机的记录列表
     * User: liubaoqiang
     * DateTime: 2024/12/10 15:44
     * @param int $member_id
     * @param string $userDeviceId
     * @return array|mixed
     */
    public function restartYunPhoneUserRecord(int $member_id, string $userDeviceId = '')
    {
        if (empty($userDeviceId)) return ['code' => 0, 'message' => '设备ID不能为空'];
        $router_url = config('yun_phone.yun_phone_router.user_restart_phone');
        $user = YunPhoneUserRegister::field('user_id')->where(['member_id' => $member_id])->find();
        if (empty($user['user_id'])) return ['code' => 0, 'message' => '用户ID不存在'];
        $params = [
            'userId'       => $user['user_id'],
            'userDeviceId' => $userDeviceId,
        ];
        $result = self::packedData($params, $router_url);
        write_log('INFO', 'YunPhoneService.php', "重启设备记录：" . json_encode($result, true), 'restart_user_yun', true);
        $code = $result['code'] ?? 0;
        if ($code != 1) return ['code' => 0, 'msg' => $result['message'] ?? '重启设备记录列表失败,请稍后再试...'];
        return $result;
    }

    /**
     * Notes: 回收设备
     * User: liubaoqiang
     * DateTime: 2024/12/10 15:58
     * @param int $member_id
     * @param string $userDeviceId
     * @return array|mixed
     */
    public static function recoveryYunPhoneUser(int $member_id, string $userDeviceId = '')
    {
        if (empty($userDeviceId)) return ['code' => 0, 'message' => '设备ID不能为空'];
        $router_url = config('yun_phone.yun_phone_router.user_recovery_phone');
        $user = YunPhoneUserRegister::field('user_id')->where(['member_id' => $member_id])->find();
        if (empty($user['user_id'])) return ['code' => 0, 'message' => '用户ID不存在'];
        $params = [
            'userId'       => $user['user_id'],
            'userDeviceId' => $userDeviceId,
        ];
        $result = self::packedData($params, $router_url);
        write_log('INFO', 'YunPhoneService.php', "回收设备：" . json_encode($result, true), 'recovery_user_yun', true);
        $code = $result['code'] ?? 0;
        if ($code != 1) return ['code' => 0, 'message' => $result['message'] ?? '回收设备记录列表失败,请稍后再试...'];
        //回收完成后, 更新设备表的状态
        YunPhoneUserMachine::where(['member_id' => $member_id, 'user_device_id' => $userDeviceId])->update(['status' => -50]);
        return $result;
    }

    /**
     * Notes: 【用户】更新用户设备有效期
     * User: liubaoqiang
     * DateTime: 2024/12/10 15:58
     * @param int $member_id
     * @param array $params
     * @return array|mixed
     */
    public static function updateYunPhoneUserValidate(int $member_id, array $params = [])
    {
        $userDeviceId = $params['userDeviceId'] ?? '';
        $validEndTime = $params['validEndTime'] ?? '';
        if (empty($userDeviceId)) return ['code' => 0, 'msg' => '设备ID不能为空'];
        if (empty($validEndTime)) return ['code' => 0, 'msg' => '更新的有效期不能为空'];
        if (strtotime($validEndTime) <= time() + 120) return ['code' => 0, 'msg' => '有效期不能小于当前时间'];
        $router_url = config('yun_phone.yun_phone_router.user_update_phone_validate');
        $user = YunPhoneUserRegister::field('user_id')->where(['member_id' => $member_id])->find();
        if (empty($user['user_id'])) return ['code' => 0, 'msg' => '用户ID不存在'];
        $params = [
            'userId'       => $user['user_id'],
            'userDeviceId' => $userDeviceId,
            'validEndTime' => $validEndTime,
        ];
        $result = self::packedData($params, $router_url);
        $code = $result['code'] ?? 0;
        if ($code != 1) return ['code' => 0, 'message' => $result['msg'] ?? '重启设备记录列表失败,请稍后再试...'];
        YunPhoneUserMachine::where(['member_id' => $member_id, 'user_device_id' => $userDeviceId])->update(['valid_end_time' => $validEndTime]);
        return $result;
    }

    /**
     * Notes: 【用户】换绑商品
     * User: liubaoqiang
     * DateTime: 2024/12/10 15:59
     * @param int $member_id
     * @param string $itemCode
     * @param string $userDeviceId
     * @return array|mixed
     */
    public function exchangeMachineYunPhoneUser(int $member_id, string $itemCode = '', string $userDeviceId = '')
    {
        if (empty($userDeviceId)) return ['code' => 0, 'msg' => '设备ID不能为空'];
        if (empty($itemCode)) return ['code' => 0, 'msg' => '换绑的商品编码不能为空'];
        $router_url = config('yun_phone.yun_phone_router.user_exchange_machine_phone');
        $user = YunPhoneUserRegister::field('user_id')->where(['member_id' => $member_id])->find();
        if (empty($user['user_id'])) return ['code' => 0, 'msg' => '用户ID不存在'];
        $params = [
            'itemCode'     => $itemCode,
            'userId'       => $user['user_id'],
            'userDeviceId' => $userDeviceId,
        ];
        $result = self::packedData($params, $router_url);
        $code = $result['code'] ?? 0;
        if ($code != 1) return ['code' => 0, 'msg' => $result['msg'] ?? '换绑商品失败,请稍后再试...'];
        return $result;
    }

    /**
     * Notes: 【SDK】获取 ClientToken 接口（此 token 使用在sdk）
     * User: liubaoqiang
     * DateTime: 2024/12/17 18:31
     * @param int $member_id
     * @return array|void
     */
    public static function getSdkToken(int $member_id)
    {
        $redis = new Redis(getRedisConfig());
        $redisData = $redis->get('sdk_token_' . $member_id);
        if(!empty($redisData)) return json_decode($redisData,true);
        $router_url = config('yun_phone.yun_phone_router.client_auth_token');
        $user = YunPhoneUserRegister::field('user_id')->where(['member_id' => $member_id])->find();
        if (empty($user['user_id'])) return ['code' => 0, 'message' => '用户ID不存在'];
        $params = [
            'userId' => $user['user_id'],
        ];
        $result = self::packedData($params, $router_url);
        write_log('INFO', 'YunPhoneService.php', "用户:" . $member_id . ",sdk使用的临时ClientToken：" . json_encode($result, true), 'client_auth_token', true);
        $code = $result['code'] ?? 0;
        if ($code != 1) return ['code' => 0, 'message' => $result['message'] ?? '获取临时Token失败,请稍后再试...'];
        $expire_time = $result['data']['expiredTimes'] ?? 0;
        if ($expire_time <= 0) return ['code' => 0, 'message' => '获取临时Token失败,请稍后再试...'];
        $redis->set('sdk_token_' . $member_id, json_encode($result,true), $expire_time - 3600);
        return $result;
    }

    /**
     * Notes: 修改云机名称
     * User: liubaoqiang
     * DateTime: 2024/12/31 09:35
     * @param $member_id
     * @param $userDeviceId
     * @param $name
     * @return array
     */
    public function setYunPhoneName($member_id, $userDeviceId, $name): array
    {
        if(!$member_id) return ['code' => 0, 'msg' => '用户ID不能为空'];
        if (empty($userDeviceId)) return ['code' => 0, 'msg' => '设备ID不能为空'];
        if (empty($name)) return ['code' => 0, 'msg' => '设备名称不能为空'];
        $result = (new YunPhoneUserMachine())->where(['user_device_id' => $userDeviceId, 'member_id' => $member_id])->find();
        if(empty($result)) return ['code' => 0, 'msg' => '设备不存在'];
        $result->__set('name', $name);;
        $res = $result->save();
        if(!$res) return ['code' => 0, 'msg' => '修改失败'];
        return ['code' => 1, 'msg' => '修改成功'];
    }


    /**
     * Notes: 请求数据总装
     * User: liubaoqiang
     * DateTime: 2024/12/10 10:36
     * @param array $params
     * @param string $router
     * @param string $url
     * @return array|mixed
     */
    public static function packedData(array $params = [], string $router = '', string $url = '')
    {
        if (empty($router) || empty($params)) return api_message([], '缺少必要参数', 0);
        if (empty($url)) {
            $postUrl = env('YUN_PHONE_API.API_URL') . $router;
        } else {
            $postUrl = $url . $router;
        }
        $time = round(microtime(true) * 1000);
        $sign = self::commonSign($params, $time);
        $header = self::commonHeader($sign, $time);
        $result = self::requestAPI($postUrl, $params, $header);
        return json_decode($result, true);
    }

    /**
     * Notes: 公共header
     * User: liubaoqiang
     * DateTime: 2024/12/10 10:40
     * @param $sign
     * @param $time
     * @return string[]
     */
    public static function commonHeader($sign, $time): array
    {
        // 设置请求头
        return [
            "APP_LICENSE_ID: " . env('YUN_PHONE_API.APP_LICENSE_ID'),
            "APP_TIME: " . $time,
            "SERVER_TOKEN: " . env('YUN_PHONE_API.SERVER_TOKEN'),
            "SIGN: $sign",
            "REGION_CODE: " . env('YUN_PHONE_API.REGION_CODE'),
            "Content-Type: application/json"
        ];
    }

    /**
     * Notes: 签名验证
     * User: liubaoqiang
     * DateTime: 2024/12/10 10:39
     * @param $params
     * @param $time
     * @return string
     */
    public static function commonSign($params, $time): string
    {
        // 对参数进行排序并拼接成字符串
        $param_string = '';
        $param = [];
        foreach ($params as $value) {
            $param[] = rawurlencode($value);
        }
        sort($param, SORT_STRING);
        array_map(function ($value) use (&$param_string) {
            $param_string .= $value . '&';
        }, $param);
        $app_license_id = env('YUN_PHONE_API.APP_LICENSE_ID');
        $app_key = env('YUN_PHONE_API.APP_LICENSE_KEY');
        // 拼接签名字符串
        $sign_string = $time . $app_license_id . $app_key . $param_string;
        return hash_hmac('sha256', $sign_string, $app_key);
    }

    /**
     * Notes: curl请求
     * User: liubaoqiang
     * DateTime: 2024/12/10 10:40
     * @param $url
     * @param $data
     * @param $header
     * @return bool|string
     */
    public static function requestAPI($url, $data, $header)
    {
        // 模拟提交数据函数
        $curl = curl_init(); // 启动一个CURL会话
        curl_setopt($curl, CURLOPT_URL, $url); // 要访问的地址
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); // 对认证证书来源的检查
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0); // 从证书中检查SSL加密算法是否存在
        curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); // 使用自动跳转
        curl_setopt($curl, CURLOPT_AUTOREFERER, 1); // 自动设置Referer
        curl_setopt($curl, CURLOPT_POST, 1); // 发送一个常规的Post请求
        curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data)); // Post提交的数据包
        curl_setopt($curl, CURLOPT_TIMEOUT, 30); // 设置超时限制防止死循环
        curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // 获取的信息以文件流的形式返回
        $tmpInfo = curl_exec($curl); // 执行操作
        if (curl_errno($curl)) {
            //echo 'Errno' . curl_error($curl);//捕抓异常
            write_log('ERROR', 'YunPhoneService', '云手机第三方请求异常:' . json_encode($data) . '--' . curl_error($curl), 'yun_phone_error');
        }
        curl_close($curl); // 关闭CURL会话
        return $tmpInfo; // 返回数据，json格式

    }

}
